package cc.lishixi.app002;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;

public class TestRepaint {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame();
        jFrame.setTitle("TEST MyButton");
        jFrame.setSize(new Dimension(800, 300));
        jFrame.setLocation(new Point(200, 300));
        jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        JPanel jPanel = new JPanel(new FlowLayout());

        MyButton btn = new MyButton();
        btn.setText("TEST");
        jPanel.add(btn);
        jFrame.add(jPanel);


        jFrame.setVisible(true);
    }

    public static class MyButton extends JButton {
        @Override
        public void paint(Graphics g) {
            //super.paint(g);
            setSize(100, 300);
            g.drawRoundRect(2, 2, 60, 30, 10, 10);
            Font font = g.getFont().deriveFont(Font.PLAIN);
            g.setFont(font);
            g.drawString("test", 20, 20);
        }

        @Override
        protected void processMouseEvent(MouseEvent e) {

            System.out.println(e.getClickCount());
            super.processMouseEvent(e);
        }
    }
}
